package com.eventur;

import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TabHost.OnTabChangeListener;

public class ListViewActivity extends Activity implements LocationListener,
OnTabChangeListener {

	ListView list;
	LazyAdapter adapter;
	TextView textView = null;

	private static String tag = "ListViewActivity";

	private LocationManager locationManager;
	private Location location = null;
	private static double currentLatitude = 0.0;
	private static double currentLongitude = 0.0;

	private static final int MENU_HOME = Menu.FIRST;
	private static final int MENU_QUIT = Menu.FIRST+1;

	public ArrayList<Event> eventsList = null;
	public ArrayList<Event> todayEventsList = null;
	public ArrayList<Event> tomorrowEventsList = null;
	public ArrayList<Event> weekEventsList = null;

	private static String category = null;
	private static String attribute = null;
	private static String searchValue = null;
	/*private TabHost tabHost;
	private static final String LIST_ALL = "All Events";
	private static final String LIST_TODAY = "Events Today";
	private static final String LIST_TOMORROW = "Events Tomorrow";
	private static final String LIST_FUTURE = "Events in the Future";*/

	ListEvents listEvents = new ListEvents();
	Event event = new Event();

	//private HashMap<String, ArrayList<Event>> collection = null;

	@Override
	public void onStart() {
		super.onStart();
		// eventsList.clear();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		eventsList.clear();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0, MENU_HOME, 0, "Home");
		//menu.add(0,MENU_QUIT,1,"Quit");
		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case MENU_HOME:
			Intent intent = new Intent(this, HomeActivity.class);
			startActivity(intent);
			this.finish();
			return true;
			/*case MENU_QUIT: int pid = android.os.Process.myPid();
			android.os.Process.killProcess(pid); finish();
			return true;*/
		}
		return false;

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		eventsList = new ArrayList<Event>();
		Bundle bundle = getIntent().getExtras();
		if (bundle != null) {

			eventsList.clear();
			category = bundle.getString("category");

			if (category.equalsIgnoreCase("My Location")
					|| category.equalsIgnoreCase("Map")) {
				final Bundle b = new Bundle();

				locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
				locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
				location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
				try {
					System.out.println("Fetching Location:");
					currentLatitude = location.getLatitude();
					currentLongitude = location.getLongitude();
					System.out.println("latitude/long obtained:"
							+ currentLatitude + ":" + currentLongitude);
				} catch (Exception e) {
					try {
						while (location.getLatitude() == 0.0
								|| location.getLongitude() == 0)
							locationManager.requestLocationUpdates(
									LocationManager.NETWORK_PROVIDER, 0, 0,
									this);

					} catch (Exception ex) {

					}
				}

				// interchanging values here
				currentLongitude = location.getLongitude();
				currentLatitude = location.getLatitude();

				b.putDouble("currentLatitude", currentLatitude);
				b.putDouble("currentLongitude", currentLongitude);

				if (category.equalsIgnoreCase("Map")) {
					Intent intent = new Intent(ListViewActivity.this,
							MapViewActivity.class);
					b.putString("key", "all");
					intent.putExtras(b);
					startActivity(intent);
					this.finish();

				} else {
					eventsList.clear();
					System.out.println("placing the current lat lon in bundle:"
							+ currentLatitude + currentLongitude);
					setContentView(R.layout.simplelistview);
					textView = (TextView) findViewById(R.id.header);

					final ListView list1 = (ListView) findViewById(R.id.ListView02);
					textView.setText("Events around you");
					eventsList = listEvents.getListByLocation(currentLatitude,
							currentLongitude);
					if (eventsList.size() != 0) {
						final String[] eventTitleArray = new String[eventsList
						                                            .size()];
						String[] eventDateArray = new String[eventsList.size()];
						String[] eventImageLinkArray = new String[eventsList
						                                          .size()];
						Event event = new Event();
						for (int i = 0; i < eventsList.size(); i++) {
							event = eventsList.get(i);
							eventTitleArray[i] = event.getTitle();
							if (event.getDistance() != 0.0){
								if(event.getTitle().length()<42){
									eventDateArray[i] = event.getsDate() + " \n "
									+ Double.toString(event.getDistance())
									+ " miles";
								}
								else{
									eventDateArray[i] = event.getsDate() + " "
									+ Double.toString(event.getDistance())
									+ " miles";
								}
							}

							else
								eventDateArray[i] = event.getsDate();
							eventImageLinkArray[i] = event.getImageLink();
							Log.i(tag, "event detail" + event.getTitle());
						}
						adapter = new LazyAdapter(ListViewActivity.this,
								eventTitleArray, eventDateArray,
								eventImageLinkArray);
						list1.setAdapter(adapter);
						list1.setFocusable(false);
						list1.setOnItemClickListener(new OnItemClickListener() {
							@Override
							public void onItemClick(AdapterView<?> arg0,
									View arg1, int position, long arg3) {
								Intent intent = new Intent(
										ListViewActivity.this,
										DisplayActivity.class);

								System.out.println("position in list:"
										+ position);
								System.out.println("title name in the list:"
										+ eventTitleArray[position]);
								System.out
								.println("placing the current lat lon in bundle:"
										+ currentLatitude
										+ currentLongitude);
								b.putString("eventTitle",eventTitleArray[position]);
								b.putString("key", "single");

								intent.putExtras(b);
								startActivity(intent);

								Toast.makeText(getApplicationContext(),
										"Detailed view for the Event",
										Toast.LENGTH_SHORT).show();
							}
						});
					} else {
						/*
						 * final String [] eventTitleArray =
						 * {"No Events to Display"}; String [] eventDateArray =
						 * new String[1]; eventDateArray[0]= ""; String []
						 * eventImageLinkArray = new String[1];
						 * l1.setAdapter(new
						 * EfficientAdapter(this,eventTitleArray
						 * ,eventDateArray,eventImageLinkArray));
						 */
						final AlertDialog.Builder wrongAddressAlert = new AlertDialog.Builder(
								ListViewActivity.this);
						wrongAddressAlert.setTitle("No Events Found");
						wrongAddressAlert
						.setMessage("Please select a different category and search again");
						wrongAddressAlert.setPositiveButton("OK",
								new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								finish();
								return;
							}
						});
						wrongAddressAlert.show();

					}
				}
			} else if (category.equals("Date")) {
				setContentView(R.layout.simplelistview);
				textView = (TextView) findViewById(R.id.header);

				final ListView list1 = (ListView) findViewById(R.id.ListView02);

				attribute = bundle.getString("attribute");
				eventsList.clear();
				textView.setText("Events on "+attribute);
				eventsList = listEvents.getListByTime(attribute);
				if (eventsList.size() != 0) {
					final String[] eventTitleArray = new String[eventsList
					                                            .size()];
					String[] eventDateArray = new String[eventsList.size()];
					String[] eventImageLinkArray = new String[eventsList.size()];
					Event event = new Event();
					for (int i = 0; i < eventsList.size(); i++) {
						event = eventsList.get(i);
						eventTitleArray[i] = event.getTitle();
						if (event.getDistance() != 0.0){
							if(event.getTitle().length()<42){
								eventDateArray[i] = event.getsDate() + " \n "
								+ Double.toString(event.getDistance())
								+ " miles";
							}
							else{
								eventDateArray[i] = event.getsDate() + " "
								+ Double.toString(event.getDistance())
								+ " miles";
							}
						}
						else
							eventDateArray[i] = event.getsDate();
						eventImageLinkArray[i] = event.getImageLink();
						Log.i(tag, "event detail" + event.getTitle());
					}
					adapter = new LazyAdapter(ListViewActivity.this,
							eventTitleArray, eventDateArray,
							eventImageLinkArray);
					list1.setAdapter(adapter);
					list1.setFocusable(false);
					list1.setOnItemClickListener(new OnItemClickListener() {
						@Override
						public void onItemClick(AdapterView<?> arg0, View arg1,
								int position, long arg3) {
							Intent intent = new Intent(ListViewActivity.this,
									DisplayActivity.class);
							Bundle b = new Bundle();
							System.out.println("position in list:" + position);
							System.out.println("title name in the list:"
									+ eventTitleArray[position]);
							b
							.putString("eventTitle",
									eventTitleArray[position]);
							intent.putExtras(b);
							startActivity(intent);

							Toast.makeText(getApplicationContext(),
									"Detailed view for the Event",
									Toast.LENGTH_SHORT).show();

						}
					});
				} else {
					/*
					 * final String [] eventTitleArray =
					 * {"No Events to Display for the below Selected Time"};
					 * String [] eventDateArray = new String[1];
					 * eventDateArray[0]= attribute; String []
					 * eventImageLinkArray = new String[1]; l1.setAdapter(new
					 * EfficientAdapter
					 * (this,eventTitleArray,eventDateArray,eventImageLinkArray
					 * ));
					 */
					final AlertDialog.Builder wrongAddressAlert = new AlertDialog.Builder(
							ListViewActivity.this);
					wrongAddressAlert.setTitle("No Events Found");
					wrongAddressAlert
					.setMessage("Please select a different Date and search again");
					wrongAddressAlert.setPositiveButton("OK",
							new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							finish();
							return;
						}
					});
					wrongAddressAlert.show();
				}
			} else {
				/*setContentView(R.layout.homescreen);
				tabHost = (TabHost) findViewById(android.R.id.tabhost);
				tabHost.setup();
				tabHost.setOnTabChangedListener(ListViewActivity.this);*/

				setContentView(R.layout.simplelistview);
				final ListView list1 = (ListView) findViewById(R.id.ListView02);
				textView = (TextView) findViewById(R.id.header);

				eventsList.clear();
				attribute = bundle.getString("attribute");
				if (category.equals("search")) {
					searchValue = bundle.getString("searchValue");
					eventsList = listEvents.getListBySearch(attribute,
							searchValue);
					textView.setText("Search based on keyword : "+searchValue);
				} else {
					eventsList = listEvents.getList(category, attribute);
					System.out.println("Events under----------"+category+"-"+attribute);

					textView.setText("Events under "+category+" - "+attribute);
				}
				System.out.println("Events list size after searching:"
						+ eventsList.size());
				if (eventsList.size() != 0) {
					final String[] eventTitleArray = new String[eventsList
					                                            .size()];
					String[] eventDateArray = new String[eventsList.size()];
					String[] eventImageLinkArray = new String[eventsList.size()];
					Event event = new Event();
					for (int i = 0; i < eventsList.size(); i++) {
						event = eventsList.get(i);
						eventTitleArray[i] = event.getTitle();
						if (event.getDistance() != 0.0){
							if(event.getTitle().length()<42){
								eventDateArray[i] = event.getsDate() + " \n "
								+ Double.toString(event.getDistance())
								+ " miles";
							}
							else{
								eventDateArray[i] = event.getsDate() + " "
								+ Double.toString(event.getDistance())
								+ " miles";
							}
						}
						else
							eventDateArray[i] = event.getsDate();
						eventImageLinkArray[i] = event.getImageLink();
						Log.i(tag, "event detail" + event.getTitle());
					}
					adapter = new LazyAdapter(ListViewActivity.this,
							eventTitleArray, eventDateArray,
							eventImageLinkArray);
					list1.setAdapter(adapter);
					list1.setFocusable(false);
					list1.setOnItemClickListener(new OnItemClickListener() {
						@Override
						public void onItemClick(AdapterView<?> arg0, View arg1,
								int position, long arg3) {
							Intent intent = new Intent(ListViewActivity.this,
									DisplayActivity.class);
							Bundle b = new Bundle();
							System.out.println("position in list:" + position);
							System.out.println("title name in the list:"
									+ eventTitleArray[position]);
							b
							.putString("eventTitle",
									eventTitleArray[position]);
							intent.putExtras(b);
							startActivity(intent);

							Toast.makeText(getApplicationContext(),
									"Detailed view for the Event",
									Toast.LENGTH_SHORT).show();

						}
					});


					/*tabHost.addTab(tabHost.newTabSpec(LIST_ALL).setIndicator(
					"All Events").setContent(new TabContentFactory() {
						public View createTabContent(String arg0) {
							list = (ListView) findViewById(R.id.listAll);
							collection = listEvents.getLists(eventsList);

							todayEventsList = (ArrayList<Event>) collection
							.get("today");
							tomorrowEventsList = (ArrayList<Event>) collection
							.get("tomorrow");
							weekEventsList = (ArrayList<Event>) collection
							.get("week");
							System.out.println("In collection building:today:"
									+ todayEventsList.size() + "tomo:"
									+ tomorrowEventsList.size() + "week:"
									+ weekEventsList.size());

							Toast.makeText(
									getApplicationContext(),
									eventsList.size()
									+ " events found in this category",
									Toast.LENGTH_SHORT).show();

							try {
								System.out.println("Number of today events:"
										+ todayEventsList.size());
								System.out.println("Number of tomorrow events:"
										+ tomorrowEventsList.size());
								System.out.println("Number of week events:"
										+ weekEventsList.size());

								Event event = new Event();
								final String[] eventTitleArray = new String[eventsList
								                                            .size()];
								String[] eventDateArray = new String[eventsList
								                                     .size()];
								String[] eventImageLinkArray = new String[eventsList
								                                          .size()];

								System.out.println("Processing today list");
								for (int i = 0; i < eventsList.size(); i++) {
									event = eventsList.get(i);
									eventTitleArray[i] = event.getTitle();
									if (event.getDistance() != 0.0)
										eventDateArray[i] = event.getsDate()
										+ " \n "
										+ Double.toString(event
												.getDistance())
												+ " miles";
									else
										eventDateArray[i] = event.getsDate();
									eventImageLinkArray[i] = event
									.getImageLink();

									Log.i(tag, "event detail"
											+ event.getTitle());
								}

								adapter = new LazyAdapter(
										ListViewActivity.this, eventTitleArray,
										eventDateArray, eventImageLinkArray);
								list.setAdapter(adapter);
								list.setFocusable(false);
								list
								.setOnItemClickListener(new OnItemClickListener() {
									@Override
									public void onItemClick(
											AdapterView<?> arg0,
											View arg1, int position,
											long arg3) {
										Intent intent = new Intent(
												ListViewActivity.this,
												DisplayActivity.class);
										Bundle b = new Bundle();
										System.out
										.println("position in list:"
												+ position);
										System.out
										.println("title name in the list:"
												+ eventTitleArray[position]);
										b
										.putString(
												"eventTitle",
												eventTitleArray[position]);
										intent.putExtras(b);
										startActivity(intent);

										Toast
										.makeText(
												getApplicationContext(),
												"Detailed view for the Event",
												Toast.LENGTH_SHORT)
												.show();
									}
								});
							} catch (Exception e) {
								e.printStackTrace();
							}
							return list;
						}
					}));
					tabHost.addTab(tabHost.newTabSpec(LIST_TODAY).setIndicator(
					"Events Today").setContent(new TabContentFactory() {
						public View createTabContent(String arg0) {
							final String[] eventTitleArray;
							String[] eventDateArray;
							String[] eventImageLinkArray;

							Event event = new Event();
							System.out.println("today button clicked");

							if (todayEventsList.size() != 0
									|| eventsList.size() != 0) {

								eventTitleArray = new String[todayEventsList
								                             .size()];
								eventDateArray = new String[todayEventsList
								                            .size()];
								eventImageLinkArray = new String[todayEventsList
								                                 .size()];

								for (int i = 0; i < todayEventsList.size(); i++) {
									event = todayEventsList.get(i);
									eventTitleArray[i] = event.getTitle();
									if (event.getDistance() != 0.0)
										eventDateArray[i] = event.getsDate()
										+ " \n "
										+ Double.toString(event
												.getDistance())
												+ " miles";
									else
										eventDateArray[i] = event.getsDate();
									eventImageLinkArray[i] = event
									.getImageLink();
								}
								Log.i(tag, "today event detail"
										+ event.getTitle());
							} else {
								eventTitleArray = new String[1];
								eventDateArray = new String[1];
								eventImageLinkArray = new String[1];
								eventTitleArray[0] = "No Events Scheduled Today Under Category";
								eventDateArray[0] = "Check for Tomorrow/Future";
								eventImageLinkArray[0] = "";
							}

							adapter = new LazyAdapter(ListViewActivity.this,
									eventTitleArray, eventDateArray,
									eventImageLinkArray);
							list.setAdapter(adapter);
							list.setFocusable(false);
							list
							.setOnItemClickListener(new OnItemClickListener() {
								@Override
								public void onItemClick(
										AdapterView<?> arg0, View arg1,
										int position, long arg3) {
									Intent intent = new Intent(
											ListViewActivity.this,
											DisplayActivity.class);
									Bundle b = new Bundle();
									System.out
									.println("position in list:"
											+ position);
									System.out
									.println("title name in the list:"
											+ eventTitleArray[position]);
									b.putString("eventTitle",
											eventTitleArray[position]);
									intent.putExtras(b);
									startActivity(intent);

									Toast
									.makeText(
											getApplicationContext(),
											"Detailed view for the Event",
											Toast.LENGTH_SHORT)
											.show();

								}
							});

							return list;
						}
					}));

					tabHost.addTab(tabHost.newTabSpec(LIST_TOMORROW)
							.setIndicator("Events Tomorrow").setContent(
									new TabContentFactory() {
										public View createTabContent(String arg0) {
											final String[] eventTitleArray;
											String[] eventDateArray;
											String[] eventImageLinkArray;

											Event event = new Event();
											System.out
											.println("Tomorrow button clicked");
											if (tomorrowEventsList.size() != 0) {
												eventTitleArray = new String[tomorrowEventsList
												                             .size()];
												eventDateArray = new String[tomorrowEventsList
												                            .size()];
												eventImageLinkArray = new String[tomorrowEventsList
												                                 .size()];

												for (int i = 0; i < tomorrowEventsList
												.size(); i++) {
													event = tomorrowEventsList
													.get(i);
													eventTitleArray[i] = event
													.getTitle();
													if (event.getDistance() != 0.0)
														eventDateArray[i] = event
														.getsDate()
														+ " \n "
														+ Double
														.toString(event
																.getDistance())
																+ " miles";
													else
														eventDateArray[i] = event
														.getsDate();
													eventImageLinkArray[i] = event
													.getImageLink();

													Log
													.i(
															tag,
															"tomorrow event detail"
															+ event
															.getTitle());

												}
											} else {
												eventTitleArray = new String[1];
												eventDateArray = new String[1];
												eventImageLinkArray = new String[1];
												eventTitleArray[0] = "No Events Scheduled Tomorrow Under Category";
												eventDateArray[0] = "Check for Today/Future";
												eventImageLinkArray[0] = "";
											}
											adapter = new LazyAdapter(
													ListViewActivity.this,
													eventTitleArray,
													eventDateArray,
													eventImageLinkArray);
											list.setAdapter(adapter);
											list.setFocusable(false);
											list
											.setOnItemClickListener(new OnItemClickListener() {
												@Override
												public void onItemClick(
														AdapterView<?> arg0,
														View arg1,
														int position,
														long arg3) {
													Intent intent = new Intent(
															ListViewActivity.this,
															DisplayActivity.class);
													Bundle b = new Bundle();
													System.out
													.println("position in list:"
															+ position);
													System.out
													.println("title name in the list:"
															+ eventTitleArray[position]);
													b
													.putString(
															"eventTitle",
															eventTitleArray[position]);
													intent.putExtras(b);
													startActivity(intent);

													Toast
													.makeText(
															getApplicationContext(),
															"Detailed view for the Event",
															Toast.LENGTH_SHORT)
															.show();

												}
											});
											return list;
										}
									}));

					tabHost.addTab(tabHost.newTabSpec(LIST_FUTURE)
							.setIndicator("Future Events").setContent(
									new TabContentFactory() {
										public View createTabContent(String arg0) {

											final String[] eventTitleArray;
											String[] eventDateArray;
											String[] eventImageLinkArray;

											Event event = new Event();
											System.out
											.println("week button button clicked");
											if (weekEventsList.size() != 0) {
												eventTitleArray = new String[weekEventsList
												                             .size()];
												eventDateArray = new String[weekEventsList
												                            .size()];
												eventImageLinkArray = new String[weekEventsList
												                                 .size()];
												for (int i = 0; i < weekEventsList
												.size(); i++) {
													event = weekEventsList
													.get(i);
													eventTitleArray[i] = event
													.getTitle();
													if (event.getDistance() != 0.0)
														eventDateArray[i] = event
														.getsDate()
														+ " \n "
														+ Double
														.toString(event
																.getDistance())
																+ " miles";
													else
														eventDateArray[i] = event
														.getsDate();
													eventImageLinkArray[i] = event
													.getImageLink();

													// Log.i(tag ,
													// "weekevent detail"+event.getTitle());

												}
											} else {
												eventTitleArray = new String[1];
												eventDateArray = new String[1];
												eventImageLinkArray = new String[1];
												eventTitleArray[0] = "No Events Scheduled In Future Under Category";
												eventDateArray[0] = "Check for Today/Tomorrow";
												eventImageLinkArray[0] = "";
											}
											adapter = new LazyAdapter(
													ListViewActivity.this,
													eventTitleArray,
													eventDateArray,
													eventImageLinkArray);
											list.setAdapter(adapter);
											list.setFocusable(false);
											list
											.setOnItemClickListener(new OnItemClickListener() {
												@Override
												public void onItemClick(
														AdapterView<?> arg0,
														View arg1,
														int position,
														long arg3) {
													Intent intent = new Intent(
															ListViewActivity.this,
															DisplayActivity.class);
													Bundle b = new Bundle();
													System.out
													.println("position in list:"
															+ position);
													System.out
													.println("title name in the list:"
															+ eventTitleArray[position]);
													b
													.putString(
															"eventTitle",
															eventTitleArray[position]);
													intent.putExtras(b);
													startActivity(intent);

													Toast
													.makeText(
															getApplicationContext(),
															"Detailed view for the Event",
															Toast.LENGTH_SHORT)
															.show();

												}
											});

											return list;
										}
									}));

					tabHost.setCurrentTab(0);*/

				} else {
					/*
					 * final String [] eventTitleArray = new String [1];
					 * eventTitleArray[0]=
					 * "No Events to Display for \n"+category+" -> "+attribute;
					 * String [] eventDateArray = new String[1];
					 * eventDateArray[0]=
					 * "Select some other category to change the search text";
					 * String [] eventImageLinkArray = new String[1];
					 * l1.setAdapter(new
					 * EfficientAdapter(this,eventTitleArray,eventDateArray
					 * ,eventImageLinkArray));
					 */
					final AlertDialog.Builder wrongAddressAlert = new AlertDialog.Builder(
							ListViewActivity.this);
					wrongAddressAlert.setTitle("No Events Found");
					wrongAddressAlert
					.setMessage("Please select a different category or check the spelling and search again");
					wrongAddressAlert.setPositiveButton("OK",
							new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							finish();
							return;
						}
					});
					wrongAddressAlert.show();

				}

				// list for all

				// list content preparation for today events

				/*
				 * Button todayButton = (Button) findViewById(R.id.todayButton);
				 * todayButton.setOnClickListener(new View.OnClickListener() {
				 * public void onClick(View v) { final String []
				 * eventTitleArray; String [] eventDateArray; String []
				 * eventImageLinkArray;
				 * 
				 * Event event = new Event();
				 * System.out.println("today button clicked");
				 * 
				 * if(todayEventsList.size()!=0 || eventsList.size()!=0){
				 * 
				 * eventTitleArray = new String[todayEventsList.size()];
				 * eventDateArray = new String[todayEventsList.size()];
				 * eventImageLinkArray = new String[todayEventsList.size()];
				 * 
				 * for(int i=0;i<todayEventsList.size();i++){ event =
				 * todayEventsList.get(i); eventTitleArray[i] =
				 * event.getTitle(); if(event.getDistance()!=0.0)
				 * eventDateArray[i] = event.getsDate() +" \n "
				 * +Double.toString(event.getDistance())+" miles"; else
				 * eventDateArray[i] = event.getsDate(); eventImageLinkArray[i]
				 * = event.getImageLink(); } Log.i(tag ,
				 * "today event detail"+event.getTitle()); }else{
				 * eventTitleArray = new String[1]; eventDateArray = new
				 * String[1]; eventImageLinkArray = new String[1];
				 * eventTitleArray[0]=
				 * "No Events Scheduled Today Under Category"; eventDateArray[0]
				 * = "Check for Tomorrow/Future"; eventImageLinkArray[0] = ""; }
				 * 
				 * adapter= new LazyAdapter(ListViewActivity.this,
				 * eventTitleArray,eventDateArray,eventImageLinkArray);
				 * list.setAdapter(adapter); list.setFocusable(false);
				 * list.setOnItemClickListener(new OnItemClickListener() {
				 * 
				 * @Override public void onItemClick(AdapterView<?> arg0, View
				 * arg1, int position, long arg3) { Intent intent = new
				 * Intent(ListViewActivity.this, DisplayActivity.class); Bundle
				 * b = new Bundle();
				 * System.out.println("position in list:"+position);
				 * System.out.println
				 * ("title name in the list:"+eventTitleArray[position]);
				 * b.putString("eventTitle", eventTitleArray[position]);
				 * intent.putExtras(b); startActivity(intent);
				 * 
				 * Toast.makeText(getApplicationContext(),
				 * "Detailed view for the Event", Toast.LENGTH_SHORT).show();
				 * 
				 * 
				 * } });
				 * 
				 * } });
				 * 
				 * Button tomorrowButton = (Button)
				 * findViewById(R.id.tomorrowButton);
				 * tomorrowButton.setOnClickListener(new View.OnClickListener()
				 * { public void onClick(View v) { final String []
				 * eventTitleArray; String [] eventDateArray; String []
				 * eventImageLinkArray;
				 * 
				 * Event event = new Event();
				 * System.out.println("Tomorrow button clicked");
				 * if(tomorrowEventsList.size()!=0){ eventTitleArray = new
				 * String[tomorrowEventsList.size()]; eventDateArray = new
				 * String[tomorrowEventsList.size()]; eventImageLinkArray = new
				 * String[tomorrowEventsList.size()];
				 * 
				 * for(int i=0;i<tomorrowEventsList.size();i++){ event =
				 * tomorrowEventsList.get(i); eventTitleArray[i] =
				 * event.getTitle(); if(event.getDistance()!=0.0)
				 * eventDateArray[i] = event.getsDate() +" \n "
				 * +Double.toString(event.getDistance())+" miles"; else
				 * eventDateArray[i] = event.getsDate(); eventImageLinkArray[i]
				 * = event.getImageLink();
				 * 
				 * Log.i(tag , "tomorrow event detail"+event.getTitle());
				 * 
				 * } } else{ eventTitleArray = new String[1]; eventDateArray =
				 * new String[1]; eventImageLinkArray = new String[1];
				 * eventTitleArray[0]=
				 * "No Events Scheduled Tomorrow Under Category";
				 * eventDateArray[0] = "Check for Today/Future";
				 * eventImageLinkArray[0] = ""; } adapter= new
				 * LazyAdapter(ListViewActivity.this,
				 * eventTitleArray,eventDateArray,eventImageLinkArray);
				 * list.setAdapter(adapter); list.setFocusable(false);
				 * list.setOnItemClickListener(new OnItemClickListener() {
				 * 
				 * @Override public void onItemClick(AdapterView<?> arg0, View
				 * arg1, int position, long arg3) { Intent intent = new
				 * Intent(ListViewActivity.this, DisplayActivity.class); Bundle
				 * b = new Bundle();
				 * System.out.println("position in list:"+position);
				 * System.out.println
				 * ("title name in the list:"+eventTitleArray[position]);
				 * b.putString("eventTitle", eventTitleArray[position]);
				 * intent.putExtras(b); startActivity(intent);
				 * 
				 * Toast.makeText(getApplicationContext(),
				 * "Detailed view for the Event", Toast.LENGTH_SHORT).show();
				 * 
				 * 
				 * } });
				 * 
				 * } });
				 * 
				 * Button weekButton = (Button) findViewById(R.id.WeekButton);
				 * weekButton.setOnClickListener(new View.OnClickListener() {
				 * public void onClick(View v) { final String []
				 * eventTitleArray; String [] eventDateArray; String []
				 * eventImageLinkArray;
				 * 
				 * Event event = new Event();
				 * System.out.println("week button button clicked");
				 * if(weekEventsList.size()!=0){ eventTitleArray = new
				 * String[weekEventsList.size()]; eventDateArray = new
				 * String[weekEventsList.size()]; eventImageLinkArray = new
				 * String[weekEventsList.size()]; for(int
				 * i=0;i<weekEventsList.size();i++){ event =
				 * weekEventsList.get(i); eventTitleArray[i] = event.getTitle();
				 * if(event.getDistance()!=0.0) eventDateArray[i] =
				 * event.getsDate() +" \n "
				 * +Double.toString(event.getDistance())+" miles"; else
				 * eventDateArray[i] = event.getsDate(); eventImageLinkArray[i]
				 * = event.getImageLink();
				 * 
				 * //Log.i(tag , "weekevent detail"+event.getTitle());
				 * 
				 * } } else{ eventTitleArray = new String[1]; eventDateArray =
				 * new String[1]; eventImageLinkArray = new String[1];
				 * eventTitleArray[0]=
				 * "No Events Scheduled In Future Under Category";
				 * eventDateArray[0] = "Check for Today/Tomorrow";
				 * eventImageLinkArray[0] = ""; } adapter= new
				 * LazyAdapter(ListViewActivity.this,
				 * eventTitleArray,eventDateArray,eventImageLinkArray);
				 * list.setAdapter(adapter); list.setFocusable(false);
				 * list.setOnItemClickListener(new OnItemClickListener() {
				 * 
				 * @Override public void onItemClick(AdapterView<?> arg0, View
				 * arg1, int position, long arg3) { Intent intent = new
				 * Intent(ListViewActivity.this, DisplayActivity.class); Bundle
				 * b = new Bundle();
				 * System.out.println("position in list:"+position);
				 * System.out.println
				 * ("title name in the list:"+eventTitleArray[position]);
				 * b.putString("eventTitle", eventTitleArray[position]);
				 * intent.putExtras(b); startActivity(intent);
				 * 
				 * Toast.makeText(getApplicationContext(),
				 * "Detailed view for the Event", Toast.LENGTH_SHORT).show();
				 * 
				 * 
				 * } });
				 * 
				 * 
				 * } });
				 */
			}
		}

	}

	@Override
	public void onLocationChanged(Location location) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTabChanged(String tabId) {
		// TODO Auto-generated method stub

	}
}
